<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/common/commonPage.jsp"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Head -->
<head>
<meta charset="utf-8" />
<title>添加用户</title>
<!--Page Related styles-->
</head>
<!-- /Head -->
<!-- Body -->
<body>
<!-- 公共header start-->
<%@ include file="/WEB-INF/page/common/header.jsp"%>
<!-- 公共header end-->
<%@ include file="/WEB-INF/page/common/leftSideBar.jsp" %>
<!-- 公共left bar start -->
<!-- 公共left bar end -->
    <div id="main" role="main">
        <div id="ribbon">
            <ol class="breadcrumb">
                <li>首页</li>
                <li>用户管理</li>
                <li>添加用户</li>
            </ol>
        </div>
        <div id="content">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <div class="jarviswidget">
                        <div class="widget-body">
                            <form id="addForm" class="smart-form">
                                <fieldset>
                                    <div class="row">
                                        <section class="col col-6">
                                            <label class="label">用户名</label>
                                            <label class="input">
                                                <input type="text" name="userName" id="userName">
                                            </label>
                                        </section>
                                        <section class="col col-6">
                                            <label class="label">密码</label>
                                            <label class="input">
                                                <input type="password" name="password" id="password">
                                            </label>
                                        </section>
                                    </div>
                                    <div class="row">
                                        <section class="col col-6">
                                            <label class="label">角色</label>
                                            <label class="select">
                                                <select name="roleId" id="roleId">
                                                    <option value="9">管理员</option>
                                                    <option value="1">信息员</option>
                                                </select>
                                                <i></i>
                                            </label>
                                        </section>
                                        <section class="col col-6">
                                            <label class="label">状态</label>
                                            <label class="select">
                                                <select name="status" id="status">
                                                    <option value="1">启用</option>
                                                    <option value="0">停用</option>
                                                </select>
                                                <i></i>
                                            </label>
                                        </section>
                                    </div>
                                </fieldset>
                                <footer>
                                    <button type="submit" class="btn btn-primary">
                                        保存
                                    </button>
                                    <button type="button" class="btn btn-default" onclick="history.back()">
                                        返回
                                    </button>
                                </footer>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="${resourcesUrl}/common/js/jquery-1.8.2.min.js"></script>
    <script src="${resourcesUrl}/common/js/bootstrap/bootstrap.min.js"></script>
    <script src="${resourcesUrl}/common/js/plugin/jquery-validate/jquery.validate.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#addForm").validate({
                rules: {
                    userName: {
                        required: true,
                        minlength: 2,
                        maxlength: 20
                    },
                    password: {
                        required: true,
                        minlength: 6,
                        maxlength: 20
                    }
                },
                messages: {
                    userName: {
                        required: "请输入用户名",
                        minlength: "用户名至少2个字符",
                        maxlength: "用户名最多20个字符"
                    },
                    password: {
                        required: "请输入密码",
                        minlength: "密码至少6个字符",
                        maxlength: "密码最多20个字符"
                    }
                },
                submitHandler: function(form) {
                    $.ajax({
                        url: '${base}/user/add',
                        type: 'POST',
                        data: $(form).serialize(),
                        success: function(data) {
                            if(data.RET_CODE.toLowerCase() === 'success') {
                                alert('添加成功');
                                window.location.href = '${base}/user/list';
                            } else {
                                alert(data.RET_OBJ || '添加失败');
                            }
                        }
                    });
                    return false; // 阻止表单默认提交
                }
            });
        });
    </script>
    <%@ include file="/WEB-INF/page/common/footer.jsp"%>
</body>
</html> 